//
//  OverviewCardView.m
//  cocoapodText
//
//  Created by apple on 16/9/7.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "ShiPei.h"
#import "OverviewCardView.h"
#import <Foundation/Foundation.h>

@interface OverviewCardView()
@end

@implementation OverviewCardView

/**
 *  初始化视图属性
 *
 *  @param frame 视图frame
 *
 *  @return self
 */
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //定制View
        self.backgroundColor = [UIColor clearColor];
        self.userInteractionEnabled = YES; //设置为NO后，不再响应touch方法
        self.multipleTouchEnabled = YES;
        //控制子视图不能超出父视图的范围
        self.clipsToBounds = YES;
        //添加子视图
        [self subView];
    }
    return self;
}

//子视图懒加载
-(void)subView{
    //背景
    UIImageView *GYCardBGImage=[[UIImageView alloc]initWithFrame:[ShiPei CGRectMakeScale:0 :0 :270 :95]];
    [GYCardBGImage setUserInteractionEnabled:YES];
    [GYCardBGImage setBackgroundColor:[UIColor whiteColor]];
    [self addSubview:GYCardBGImage];
    self.GYCardBGImage=GYCardBGImage;
    //类型图片
    UIImageView *GYCardTypeImage=[[UIImageView alloc]initWithFrame:[ShiPei CGRectMakeScale:55 :15 :45 :45]];
    [GYCardTypeImage setUserInteractionEnabled:YES];
    [GYCardTypeImage setBackgroundColor:[UIColor clearColor]];
    [self addSubview:GYCardTypeImage];
    self.GYCardTypeImage=GYCardTypeImage;
    //类型描述
    UILabel *GYCardTypeLabel=[[UILabel alloc]initWithFrame:[ShiPei CGRectMakeScale:55 :60 :100 :25]];
    [GYCardTypeLabel setUserInteractionEnabled:YES];
    [GYCardTypeLabel setText:@""];
    [GYCardTypeLabel setTextColor:[UIColor whiteColor]];
    [GYCardTypeLabel setFont:[UIFont boldSystemFontOfSize:[ShiPei CGFloatMakeFontScaleWithPX:24]]];
    [self addSubview:GYCardTypeLabel];
    self.GYCardTypeLabel=GYCardTypeLabel;
    //概览信息背景
    UIView *GYCardNumberAndUnitBGView=[[UIView alloc]initWithFrame:[ShiPei CGRectMakeScale:155 :35 :110 :25]];
    [self addSubview:GYCardNumberAndUnitBGView];
    //概览
    UILabel *GYCardNumberLabel=[[UILabel alloc]initWithFrame:[ShiPei CGRectMakeScale:0 :0 :0 :25]];
    [GYCardNumberLabel setTextColor:[UIColor whiteColor]];
    [GYCardNumberLabel setText:@""];
    [GYCardNumberLabel setFont:[UIFont boldSystemFontOfSize:[ShiPei CGFloatMakeFontScaleWithPX:40]]];
    [GYCardNumberAndUnitBGView addSubview:GYCardNumberLabel];
    self.GYCardNumberLabel=GYCardNumberLabel;
    
    //概览单位
    UILabel *GYCardUnitLabel=[[UILabel alloc]initWithFrame:[ShiPei CGRectMakeScale:0 :0 :0 :25]];
    [GYCardUnitLabel setTextColor:[UIColor whiteColor]];
    [GYCardUnitLabel setText:@""];
    [GYCardUnitLabel setFont:[UIFont boldSystemFontOfSize:[ShiPei CGFloatMakeFontScaleWithPX:25]]];
    [GYCardNumberAndUnitBGView addSubview:GYCardUnitLabel];
    self.GYCardUnitLabel=GYCardUnitLabel;
    
}

-(void)setCardBGImage:(UIColor *)CardBGImageColor{
    [self.GYCardBGImage setBackgroundColor:CardBGImageColor];
}


-(void)setCardTypeImage:(NSString *)CardTypeImage{
    [self.GYCardTypeImage setImage:[UIImage imageNamed:CardTypeImage]];
}

-(void)setCardTypeLabel:(NSString *)CardTypeLabel{
    [self.GYCardTypeLabel setText:CardTypeLabel];
}
-(void)setCardNumberLabel:(NSString *)CardNumberLabel{
    CardNumberLabel=[CommonTool keepDecimal:CardNumberLabel];
    
    [self.GYCardNumberLabel setText:CardNumberLabel];
    [self.GYCardNumberLabel sizeToFit];
    CGFloat CardNumberW=self.GYCardNumberLabel.frame.size.width;
    CGFloat CardNumberH=self.GYCardNumberLabel.frame.size.height;
    CGFloat CardUnitH=self.GYCardUnitLabel.frame.size.height;
    
    CGRect UnitFrame=self.GYCardUnitLabel.frame;
    UnitFrame.origin.x=CardNumberW;
    UnitFrame.origin.y=(CardNumberH-CardUnitH)/2;
    [self.GYCardUnitLabel setFrame:UnitFrame];
}

-(void)setCardUnitLabel:(NSString *)CardUnitLabel{
    [self.GYCardUnitLabel setText:CardUnitLabel];
    [self.GYCardUnitLabel sizeToFit];
    CGFloat CardNumberW=self.GYCardNumberLabel.frame.size.width;
    CGFloat CardNumberH=self.GYCardNumberLabel.frame.size.height;
    CGFloat CardUnitH=self.GYCardUnitLabel.frame.size.height;
    
    CGRect UnitFrame=self.GYCardUnitLabel.frame;
    UnitFrame.origin.x=CardNumberW;
    UnitFrame.origin.y=(CardNumberH-CardUnitH)/2;
    [self.GYCardUnitLabel setFrame:UnitFrame];
}

//登录
-(void)setData{
    if([_delegate respondsToSelector:@selector(onSetData:)]){
        [_delegate onSetData:self];
    }
}

@end
